﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SundStudent.ModelLayer;
using SundStudent.ControlLayer;


namespace SundStudent.GUILayer
{
    public partial class AnameseForm : Form
    {
        private LektionsPatient selectedPatient;
        private PatientControler ctrlPatient = new PatientControler();

        public AnameseForm(LektionsPatient patient)
        {
            InitializeComponent();
            if (patient != null)
            {
                selectedPatient = patient;
                label1.Text = selectedPatient.Navn + " Stue:  " + selectedPatient.Stue.Stuenr + " Seng " + selectedPatient.Seng.Sengnr;
                opdaterLisBox();


            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            PatientControler ctrPatient = new PatientControler();
            String dato = dateTimePicker1.Text.ToString();
            DateTime dato1 = new DateTime();
            dato1 = DateTime.Parse(dato);
            

          
            string infokilde = textBoxInfoKildeaarsag.Text;
            string kontaktaarsag = richTextBoxKontakt.Text;
            string type;
            int rc = 0;
            if (infokilde.Length > 0)
            {
                int indexVagt = comboBox1.SelectedIndex;
                string vagt = vagtType(indexVagt);
                type = "Kontaktårsag";
                rc = ctrPatient.GemAnamnese(dato1, selectedPatient.Nr, vagt, infokilde, kontaktaarsag, type, selectedPatient.IndDato);
                infokilde = "";
                textBoxInfoKildeaarsag.Text = "";
                richTextBoxKontakt.Text = "";
                comboBox1.SelectedIndex = 0;
                comboBox2.SelectedIndex = 0;
                comboBox3.SelectedIndex = 0;
            }
             dato = dateTimePicker2.Text.ToString();
             dato1 = new DateTime();
            dato1 = DateTime.Parse(dato);
          
            infokilde = textBoxInfokildeCave.Text;
            kontaktaarsag = richTextBoxCave.Text;
            if (infokilde.Length > 0)
            {
                int indexVagt = comboBox2.SelectedIndex;
                string vagt = vagtType(indexVagt);
                type = "Cave";
                rc = rc + ctrPatient.GemAnamnese(dato1, selectedPatient.Nr, vagt, infokilde, kontaktaarsag, type, selectedPatient.IndDato);
                infokilde = "";
                textBoxInfokildeCave.Text = "";
                richTextBoxCave.Text = "";
                comboBox1.SelectedIndex = 0;
                comboBox2.SelectedIndex = 0;
                comboBox3.SelectedIndex = 0;
            }
            dato = dateTimePicker3.Text.ToString();
            dato1 = new DateTime();
            dato1 = DateTime.Parse(dato);
         
            infokilde = textBoxInfokildemed.Text;
            kontaktaarsag = richTextBox3Medicin.Text;
            if (infokilde.Length > 0)
            {
                int indexVagt = comboBox3.SelectedIndex;
                string vagt = vagtType(indexVagt);
                type = "Medicin";
                rc = rc + ctrPatient.GemAnamnese(dato1, selectedPatient.Nr, vagt, infokilde, kontaktaarsag, type, selectedPatient.IndDato);
                infokilde = "";
                textBoxInfokildemed.Text = "";
                richTextBox3Medicin.Text = "";
                comboBox1.SelectedIndex = 0;
                comboBox2.SelectedIndex = 0;
                comboBox3.SelectedIndex = 0;
            }
            if (rc > 0)
            {
                opdaterLisBox();
                labelMed.Text = "Oplysningerne er registreret";
            }

        }
        private string vagtType(int index)
        {
            string vagt = "";
            if (index == 0)
            {
                vagt = "DV";
            }
            if (index == 1)
            {
                vagt = "AF";
            }
            if (index == 2)
            {
                vagt = "NV";
            }
            return vagt;
        }
        private void opdaterLisBox()
        {
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            listBox3.Items.Clear();
            List<Anamnese> anamList = ctrlPatient.HentAllePatientensAnamnese(selectedPatient.Nr);
            if (anamList.Count > 0)
            {
                foreach (Anamnese anamObj in anamList)
                {
                    if (anamObj.Type.Equals("Kontaktårsag"))
                    {
                        listBox1.Items.Add(anamObj.Dato.Day +"." + anamObj.Dato.Month + "."+ anamObj.Dato.Year + " "+ anamObj.Vagt +"  "+ anamObj.InfoKildeKontakt + " " + anamObj.Beskrivelse);

                    }
                    if (anamObj.Type.Equals("Cave"))
                    {
                        listBox2.Items.Add(anamObj.Dato.Day + "." + anamObj.Dato.Month + "." + anamObj.Dato.Year + " " + anamObj.Vagt + "  " + anamObj.InfoKildeKontakt + " " + anamObj.Beskrivelse);

                    }
                    if (anamObj.Type.Equals("Medicin"))
                    {
                        listBox3.Items.Add(anamObj.Dato.Day + "." + anamObj.Dato.Month + "." + anamObj.Dato.Year + " " + anamObj.Vagt + "  " + anamObj.InfoKildeKontakt + " " + anamObj.Beskrivelse);

                    }
                }
            }
        }

        private void AnameseForm_Load(object sender, EventArgs e)
        {

        }
    }
}
       
        
    

